;-*- coding: utf-8 -*-
; Fritz Kunze's emacs init file.
; 2008-08
; 
; 

(add-to-list 'load-path "~/.emacs.d")


;----
; loading custom commands and functions in ~/.emacs.d
;



(message "hey fritz - we are now processing our ~/.emacs.d/init.el")

(message "hey fritz - we are loading the file ~\\.emacs.d\\init.el")

(message "hey fritz - we are loading our emacs keyboard shortcuts")

(load-file (w32-short-file-name "~/.emacs.d/keyboard.el"))


(message "hey fritz - we've finished loading our emacs keyboard shortcuts")

(message "hey fritz - we are loading a way to print files")

;;
;;It requires:
;;download prfile32.exe from http://www.lerup.com/printfile/
;;I got this from stackflow
;;

(setq is-win32 t)

(defun joc-make-fname-from-buffer-name (buffer-name-in)
  "Returns a valid filename from a given buffer name"
  (interactive "b")
  (save-match-data
    (let* ((start (string-match "[^ \*]" buffer-name-in))
           (end (string-match "[ \*]*$" buffer-name-in (match-end 0)))
           (rc (substring buffer-name-in start end)))
      ;; remove some special characters
      (while (string-match "[:]+" rc)
        (setq rc (replace-match "_" t t rc)))
      rc)))

(when is-win32
    (defun joc-print-buffer-or-region (prefix)
      "Prints buffer or region via PrintFile32.  If a prefix arg is set (via C-u) then
       the current region is printed, otherwise the current buffer is printed."

      (interactive "P")

      ;; ----- set the print directory, fname and args -----
      (let* ((print-dir (expand-file-name "~/emacs/print"))
             (print-fname (joc-make-fname-from-buffer-name (buffer-name)))
             (print-fullpath (concat print-dir "/" print-fname))
             (print-args "/delete")
             ;; ----- set rstart and rend to the current region -----
             (rstart (point-min)) (rend (point-max)))

        ;; ----- if prefix given, set them to region -----
        (if (and prefix)
            (if (and (point) (mark) (/= (point) (mark)))
                (progn (setq rstart (min (point) (mark)))
                       (setq rend (max (point) (mark))))
              (error "No region defined")))

        ;; ----- make the directory -----
        (if (not (file-directory-p print-dir))
            (make-directory print-dir))

        ;; ----- write buffer/region to a temp file, print it, delete directory -----
        (write-region rstart rend print-fullpath)
        (call-process "prfile32" nil t nil print-args print-fullpath)
        (delete-directory print-dir))))

(message "hey fritz - we finished loading a way to print files")

(message "hey fritz - we are loading our emacs_abbrevs.el")

(load-file (w32-short-file-name "~/.emacs.d/emacs_abbrevs.el"))

(message "hey fritz - we've finished loading our emacs_abbrevs.el")

(message "hey fritz - we are loading our elisp_util.el")

(load-file (w32-short-file-name "~/.emacs.d/elisp_util.el"))

(message "hey fritz - we've finished loading our elisp_util.el")

(message "hey fritz - we are loading our rst_mods.el which add functionality to rst-mode")

(load-file (w32-short-file-name "~/.emacs.d/rst_mods.el"))

(message "hey fritz - we've finished loading our rst_mode.el")

(message "hey fritz - we are trying to make recent files possible through ido-mode")

(require 'ido)
(ido-mode 1)
(ido-everywhere 1)
(setq ido-enable-flex-matching t)
(setq ido-create-new-buffer 'always)
(setq ido-confirm-unique-completion nil) ;; wait for RET, even for unique?
(setq ido-show-dot-for-dired t) ;; put . as the first item
(setq ido-use-filename-at-point t) ;; prefer file names near point

;;Uniquify

;; I use uniquify to distinguish between two identically named files as the default, appending a <n> extension, is rubbish. This tip is from Trey Jackson (http://trey-jackson.blogspot.com/2008/01/emacs-tip-11-uniquify.html)

(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "|")
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")



(defun recentf-ido-find-file ()
  "Find a recent file using Ido."
  (interactive)
  (let* ((file-assoc-list
	  (mapcar (lambda (x)
		    (cons (file-name-nondirectory x)
			  x))
		  recentf-list))
	 (filename-list
	  (remove-duplicates (mapcar #'car file-assoc-list)
			     :test #'string=))
	 (filename (ido-completing-read "Choose recent file: "
					filename-list
					nil
					t)))
    (when filename
      (find-file (cdr (assoc filename
			     file-assoc-list))))))
(global-set-key "\C-x\ \C-r" 'recentf-ido-find-file)


;; Display Completions Vertically

;; It’s a lot easier to scan long path names if they’re displayed vertically, instead of horizontally. Run this to achieve just that:

(setq ido-decorations (quote ("\n-> " "" "\n   " "\n   ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")))

;;You’ll want to set truncate-lines to nil if you do this.

  (defun my-ido-minibuffer-setup-hook ()
    ;; allow line wrapping in the minibuffer
    (set (make-local-variable 'truncate-lines) nil))
  (add-hook 'ido-minibuffer-setup-hook 'my-ido-minibuffer-setup-hook)

(message "hey fritz - we finished load code to make recent files possible through ido-mode")

;(message "hey fritz - we are loading xah lee's command-frequence.el package to figure out which commands we use the most")

;; Set up a way to keep track of command frequencies I use in emacs
;; taken from http://xahlee.org/emacs/command-frequency.html
;; and http://nflath.com/2009/08/command-frequency-mode/
;; and later I took an update to command-frequency.el from 
;; http://code.google.com/p/ergoemacs/source/browse/trunk/packages/command-frequency.el?spec=svn200&r=200


;(load-file (w32-short-file-name "~/.emacs.d/command-frequency.el"))

;;(setq-default command-frequency-table-file (w32-short-file-name "~/.emacs.d/frequencies"))
;(require 'command-frequency)
;(command-frequency-mode 1)
;(command-frequency-table-load)
;(command-frequency-autosave-mode 1)


;;(message "hey fritz - we've finished loading command-frequence.el")

;; (message "hey fritz - we are loading drew adam's browse-kill-ring+.el package")

;; ;;; browse-kill-ring+

;; (load-file (w32-short-file-name "~/.emacs.d/second-sel.el"))
;; (require 'second-sel)

;; (load-file (w32-short-file-name "~/.emacs.d/browse-kill-ring.el"))
;; (require 'browse-kill-ring)

;; (load-file (w32-short-file-name "~/.emacs.d/browse-kill-ring+.el"))
;; (require 'browse-kill-ring+)

;; (message "hey fritz - we finished loading drew adam's browse-kill-ring+.el package")

;; To load custom changes to emacs, put them in your own directory and load packages out of this directory first.  This way, emacs will load changes you add, and ignore packages with the same name when it loads from the default load path. 


	

;; I am currently using GNU Emacs 23.0.93.1 in Windows Vista SP1. In my .emacs file I make a call to (server-start) and that is causing an error with the message The directory ~/.emacs.d/server is unsafe. Has anyone seen this and know a fix or workaround? ... other than leaving server turned off ;)

;; Here is the stack trace:

;; Debugger entered--Lisp error: (error "The directory ~/.emacs.d/server is unsafe")
;;   signal(error ("The directory ~/.emacs.d/server is unsafe"))
;;   error("The directory %s is unsafe" "~/.emacs.d/server")
;;   server-ensure-safe-dir("~\\.emacs.d\\server\\")
;;   server-start(nil)
;;   call-interactively(server-start t nil)
;;   execute-extended-command(nil)
;;   call-interactively(execute-extended-command nil nil)

;; This is a known Emacs bug on Windows. A workaround is to comment out this line in server-ensure-safe-dir in server.el the you'll want to byte recompile after the change:

;; ;; FIXME: Busted on Windows. 
;; ;; (eql (nth 2 attrs) (user-uid))

;; To avoid hacking in the lisp directory, you can just add the following to your .emacs:

;; (and (= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))



;;(and (= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))
(server-start)

(message "hey fritz - we've set up runemacs and emacsclientw.exe")

(require 'help-fns+)

(message "hey fritz - we've set up help-fns.el - an easier way to read help on emacs")

;; get an indication of when the end of file occurs - note this is a strange lisp form...
(setq-default indicate-empty-lines t)

;; The following customization will tell remember to use org files as
;; target, and to create annotations compatible with Org-mode links.


(add-to-list 'load-path "~/.emacs.d/org-6.36/lisp")
(add-to-list 'load-path "~/.emacs.d/org-6.36/contrib/lisp")

;; These are just some general org-mode customizations to make org better. I don’t like org inserting blank lines, and I do like ido. org-insert-heading-respect-content will make new headings appear after the content for the current one, which is usually the behavior I want. Allowing return to follow links makes navigation much easier. org-special-ctrl-a/e will rebind ctrl-a and ctrl-e to make more sense in org mode, going to the beginning and end of the heading instead of the current line. This is actually a bit inaccurate - ctrl-a cycles between beginning of heading and beginning of line, which helps with speed commands. Enabling speed commands will rebind certain one-letter keybindings when the cursor is at the beginning of the row - most notably ‘t’ for org-todo instead of ‘C-c C-t’, a huge increase in efficiency.
;; taken from http://nflath.com/2010/03/org-mode-2/

(setq org-completion-use-ido t)
(setq org-blank-before-new-entry '((heading . nil) (plain-list-item . nil)))
(setq org-completion-use-ido t)
(setq org-insert-heading-respect-content t)
(setq org-return-follows-link t)
(setq org-special-ctrl-a/e t)
(setq org-use-speed-commands t)
(setq org-speed-commands-user nil)


;; Org mode allows you to clock the time you spend on specific tasks in a project. When you start working on an item, you can start the clock. When you stop working on that task, or when you mark the task done, the clock is stopped and the corresponding time interval is recorded. It also computes the total time spent on each subtree of a project. And it remembers a history or tasks recently clocked, to that you can jump quickly between a number of tasks absorbing your time.
;; 
;; To save the clock history across Emacs sessions, use 
;; 

(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)



;; The following lines are always needed.  Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
;;

;;
;;
;; Experiments with automatic date creation on new nodes
;; C-c i inserts the time stamp
;; C-u M-x apropos org-insert-time-stamp ... finds help
;;

(defun bh/insert-inactive-timestamp ()
  (interactive)
  (save-excursion
    ;(insert "\n")
    (org-cycle)
    (org-insert-time-stamp nil t t nil nil nil)))

(global-set-key (kbd "C-c i") 'bh/insert-inactive-timestamp)


(add-hook 'org-insert-heading-hook 'bh/insert-inactive-timestamp)


(add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only
;;;With this setup, all files with extension ‘.org’ will be put into Org mode. 

;; set up org publishing following: 
;; http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.php
;;


(message "hey fritz - org mode loading is done - try out - M-x org-mde see: C:\NP1\Get Organized with Emacs Org-mode.htm")

(message "hey fritz - we are loading our org-projects.el which defines how we publish org-mode files")

(load-file (w32-short-file-name "~/.emacs.d/org-projects.el"))

(message "hey fritz - we've finished loading our org-projects.el")

(message "hey fritz - we are loading wiegley code for using org and gtd")

(require 'org-install)


(define-key mode-specific-map [?a] 'org-agenda)

(eval-after-load "org"
  '(progn
     (define-prefix-command 'org-todo-state-map)

     (define-key org-mode-map "\C-cx" 'org-todo-state-map)

     (define-key org-todo-state-map "x"
       #'(lambda nil (interactive) (org-todo "CANCELLED")))
     (define-key org-todo-state-map "d"
       #'(lambda nil (interactive) (org-todo "DONE")))
     (define-key org-todo-state-map "f"
       #'(lambda nil (interactive) (org-todo "DEFERRED")))
     (define-key org-todo-state-map "l"
       #'(lambda nil (interactive) (org-todo "DELEGATED")))
     (define-key org-todo-state-map "s"
       #'(lambda nil (interactive) (org-todo "STARTED")))
     (define-key org-todo-state-map "w"
       #'(lambda nil (interactive) (org-todo "WAITING")))

     (define-key org-agenda-mode-map "\C-n" 'next-line)
     (define-key org-agenda-keymap "\C-n" 'next-line)
     (define-key org-agenda-mode-map "\C-p" 'previous-line)
     (define-key org-agenda-keymap "\C-p" 'previous-line)))

(require 'remember)
(org-remember-insinuate)
;(define-key global-map "\C-cr" 'org-remember)


(add-hook 'remember-mode-hook 'org-remember-apply-template)

(define-key global-map [(control meta ?r)] 'remember)

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(abbrev-mode t)
 '(column-number-mode t)
 '(current-language-environment "UTF-8")
 '(default-frame-alist (quote ((font . "-outline-Courier New-normal-r-normal-normal-21-157-96-96-c-*-iso8859-1") (top . 10) (left . 150) (tool-bar-lines . 1) (menu-bar-lines . 1) (right-fringe) (left-fringe))))
 '(doc-view-ghostscript-program (executable-find "mgs"))
 '(focus-follows-mouse nil)
 '(global-visual-line-mode t)
 '(grep-command "C:\\Windows\\System32\\findstr.exe -n -r  ")
 '(grep-use-null-device t)
 '(gud-pdb-command-name "python -m pdb")
 '(icicle-reminder-prompt-flag 0)
 '(ido-max-work-directory-list 80)
 '(ido-max-work-file-list 50)
 '(ido-mode (quote both) nil (ido))
 '(inhibit-startup-echo-area-message "fkunze")
 '(inhibit-startup-screen t)
 '(ispell-program-name "C:\\Program Files\\Aspell\\bin\\aspell.exe")
 '(mouse-autoselect-window t)
 '(mouse-wheel-follow-mouse t)
 '(org-agenda-custom-commands (quote (("d" todo "DELEGATED" nil) ("c" todo "DONE|DEFERRED|CANCELLED" nil) ("w" todo "WAITING" nil) ("W" agenda "" ((org-agenda-ndays 21))) ("A" agenda "" ((org-agenda-skip-function (lambda nil (org-agenda-skip-entry-if (quote notregexp) "\\=.*\\[#A\\]"))) (org-agenda-ndays 1) (org-agenda-overriding-header "Today's Priority #A tasks: "))) ("u" alltodo "" ((org-agenda-skip-function (lambda nil (org-agenda-skip-entry-if (quote scheduled) (quote deadline) (quote regexp) "<[^>
]+>"))) (org-agenda-overriding-header "Unscheduled TODO entries: "))))))
 '(org-agenda-files (quote ("~/mydrop~1/todo.org")))
 '(org-agenda-ndays 7)
 '(org-agenda-show-all-dates t)
 '(org-agenda-skip-deadline-if-done t)
 '(org-agenda-skip-scheduled-if-done t)
 '(org-agenda-start-on-weekday nil)
 '(org-deadline-warning-days 14)
 '(org-default-notes-file "~/mydrop~1/notes.org")
 '(org-directory "~/OrgProjects")
 '(org-fast-tag-selection-single-key (quote expert))
 '(org-icalendar-include-todo t)
 '(org-remember-store-without-prompt t)
 '(org-remember-templates (quote ((116 "* TODO %?
  %u" "~/mydrop~1/todo.org" "Tasks") (110 "* %u %?" "~/mydrop~1/notes.org" "Notes"))))
 '(org-reverse-note-order t)
 '(org-support-shift-select t)
 '(org-todo-keyword-faces (quote (("TODO" :foreground "medium blue" :weight bold) ("APPT" :foreground "medium blue" :weight bold) ("NOTE" :foreground "brown" :weight bold) ("STARTED" :foreground "dark orange" :weight bold) ("WAITING" :foreground "red" :weight bold) ("DELEGATED" :foreground "dark violet" :weight bold) ("DEFERRED" :foreground "dark blue" :weight bold) ("SOMEDAY" :foreground "dark blue" :weight bold))))
 '(org-todo-keywords (quote ((sequence "TODO" "APPT" "|" "DONE" "NOTE"))))
 '(python-python-command "C:/Python25/python.exe")
 '(recentf-max-saved-items 40)
 '(remember-annotation-functions (quote (org-remember-annotation)))
 '(remember-handler-functions (quote (org-remember-handler)))
 '(safe-local-variable-values (quote ((after-save-hook archive-done-tasks) (after-save-hook sort-done-tasks) (after-save-hook commit-after-save))))
 '(show-paren-mode t)
 '(text-mode-hook (quote (turn-on-flyspell text-mode-hook-identify))))



(message "hey fritz - we finished loading wiegley code for using org and gtd")

(message "hey fritz - we are loading wiegley-org.el code for using org and gtd")

(add-to-list 'load-path "~/.emacs.d/wiegley-org.el")

;; I ran into problems trying to make the wiegley's org-stuff work with my todo list.  So I just started taking code from his emacs.el file on 4-27-10.  I seem to get this stuff to work.  And I put this after the load of wiegley-org.el, which also seems to contain some duplicate defintions that may be overridden by what i inserted below.  I have to figure out what he has done, and in the process i will learn quite a bit about org-mode todo lists.

(defun org-insert-bug (bug)
  (interactive "nBug: ")
  (insert (format "[[cegbug:%s][#%s]]" bug bug)))

(defun org-my-state-after-clock-out (state)
  (if (string= state "STARTED")
      "TODO"
    state))

(defun replace-named-dates ()
  (interactive)
  (while (re-search-forward
	  "-\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)-"
	  nil t)
    (let ((mon (match-string 1)))
      (replace-match
       (format "/%s/"
	       (cond ((equal mon "Jan") "01")
		     ((equal mon "Feb") "02")
		     ((equal mon "Mar") "03")
		     ((equal mon "Apr") "04")
		     ((equal mon "May") "05")
		     ((equal mon "Jun") "06")
		     ((equal mon "Jul") "07")
		     ((equal mon "Aug") "08")
		     ((equal mon "Sep") "09")
		     ((equal mon "Oct") "10")
		     ((equal mon "Nov") "11")
		     ((equal mon "Dec") "12")))))))


(defvar org-my-archive-expiry-days 7
  "The number of days after which a completed task should be auto-archived.
This can be 0 for immediate, or a floating point value.")

(defconst org-my-ts-regexp "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]>\r\n]*?\\)[]>]"
  "Regular expression for fast inactive time stamp matching.")

(defun org-my-closing-time ()
  (let* ((state-regexp
	  (concat "- State \"\\(?:" (regexp-opt org-done-keywords)
		  "\\)\"\\s-*\\[\\([^]\n]+\\)\\]"))
	 (regexp (concat "\\(" state-regexp "\\|" org-my-ts-regexp "\\)"))
	 (end (save-excursion
		(outline-next-heading)
		(point)))
	 begin
	 end-time)
    (goto-char (line-beginning-position))
    (while (re-search-forward regexp end t)
      (let ((moment (org-parse-time-string (match-string 1))))
	(if (or (not end-time)
		(time-less-p (apply #'encode-time end-time)
			     (apply #'encode-time moment)))
	    (setq end-time moment))))
    (goto-char end)
    end-time))

;; (defun org-my-archive-done-tasks ()
;;   (interactive)
;;   (save-excursion
;;     (goto-char (point-min))
;;     (let ((done-regexp
;; 	   (concat "^\\*\\* \\(" (regexp-opt org-done-keywords) "\\) ")))
;;       (while (re-search-forward done-regexp nil t)
;; 	(if (>= (time-to-number-of-days
;; 		 (time-subtract (current-time)
;; 				(apply #'encode-time (org-my-closing-time))))
;; 		org-my-archive-expiry-days)
;; 	    (org-archive-subtree))))
;;     (save-buffer)))

(defvar org-my-archive-expiry-days 2
  "The number of days after which a completed task should be auto-archived.
This can be 0 for immediate, or a floating point value.")

(defun org-my-archive-done-tasks ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (let ((done-regexp
           (concat "\\* \\(" (regexp-opt org-done-keywords) "\\) "))
          (state-regexp
           (concat "- State \"\\(" (regexp-opt org-done-keywords)
                   "\\)\"\\s-*\\[\\([^]\n]+\\)\\]")))
      (while (re-search-forward done-regexp nil t)
        (let ((end (save-excursion
                     (outline-next-heading)
                     (point)))
              begin)
          (goto-char (line-beginning-position))
          (setq begin (point))
          (if (re-search-forward state-regexp end t)
              (let* ((time-string (match-string 2))
                     (when-closed (org-parse-time-string time-string)))
                (if (>= (time-to-number-of-days
                         (time-subtract (current-time)
                                        (apply #'encode-time when-closed)))
                        org-my-archive-expiry-days)
                    (org-archive-subtree)))
            (goto-char end)))))
    (save-buffer)))

(setq safe-local-variable-values (quote ((after-save-hook archive-done-tasks))))

(defalias 'archive-done-tasks 'org-my-archive-done-tasks)


;; (defun org-get-inactive-time ()
;;   (let ((begin (point)))
;;     (save-excursion
;;       (outline-next-heading)
;;       (if (re-search-backward org-my-ts-regexp begin t)
;; 	  (let ((time (float-time (org-time-string-to-time (match-string 0)))))
;; 	    (assert (floatp time))
;; 	    time)
;; 	(debug)))))

;; (defun org-get-completed-time ()
;;   (let ((begin (point)))
;;     (save-excursion
;;       (outline-next-heading)
;;       (and (re-search-backward "\\(- State \"\\(DONE\\|DEFERRED\\|CANCELLED\\)\"\\s-+\\[\\(.+?\\)\\]\\|CLOSED: \\[\\(.+?\\)\\]\\)" begin t)
;; 	   (time-to-seconds (org-time-string-to-time (or (match-string 3)
;; 							 (match-string 4))))))))

;; (defun org-my-sort-done-tasks ()
;;   (interactive)
;;   (goto-char (point-min))
;;   (org-sort-entries-or-items t ?F #'org-get-inactive-time #'<)
;;   (goto-char (point-min))
;;   (while (re-search-forward "


;; +" nil t)
;;     (delete-region (match-beginning 0) (match-end 0))
;;     (insert "
;; "))
;;   (let (after-save-hook)
;;     (save-buffer))
;;   (org-overview))

;; (defalias 'sort-done-tasks 'org-my-sort-done-tasks)

;; (defun org-maybe-remember (&optional done)
;;   (interactive "P")
;;   (if (string= (buffer-name) "*Remember*")
;;       (call-interactively 'org-ctrl-c-ctrl-c)
;;     (if (null done)
;; 	(call-interactively 'org-remember)
;;       (let ((org-remember-templates
;; 	     '((110 "* STARTED %?
;;   - State \"STARTED\"    %U
;;   SCHEDULED: %t
;;   :PROPERTIES:
;;   :ID:       %(shell-command-to-string \"uuidgen\")  :END:
;;   %U" "~/Dropbox/todo.txt" "Inbox"))))
;; 	(org-remember)))))

;; (defun org-inline-note ()
;;   (interactive)
;;   (switch-to-buffer-other-window "todo.txt")
;;   (goto-char (point-min))
;;   (re-search-forward "^\\* Inbox$")
;;   (re-search-forward "^  :END:")
;;   (forward-line)
;;   (goto-char (line-beginning-position))
;;   (insert "** NOTE ")
;;   (save-excursion
;;     (insert (format "
;;    :PROPERTIES:
;;    :ID:       %s   :VISIBILITY: folded
;;    :END:
;;    " (shell-command-to-string "uuidgen")))
;;     (org-insert-time-stamp nil t 'inactive)
;;     (insert ?\n))
;;   (save-excursion
;;     (forward-line)
;;     (org-cycle)))

;; (defun org-remember-note ()
;;   (interactive)
;;   (if (string= (buffer-name) "*Remember*")
;;       (call-interactively 'org-ctrl-c-ctrl-c)
;;     (let ((org-remember-templates
;; 	   '((110 "* NOTE %?
;;   :PROPERTIES:
;;   :ID:       %(shell-command-to-string \"uuidgen\")  :VISIBILITY: folded
;;   :END:
;;   %U" "~/Dropbox/todo.txt" "Inbox"))))
;;       (call-interactively 'org-remember))))

;; (defun org-get-message-link ()
;;   (let ((subject (do-applescript "tell application \"Mail\"
;;         set theMessages to selection
;;         subject of beginning of theMessages
;; end tell"))
;;         (message-id (do-applescript "tell application \"Mail\"
;;         set theMessages to selection
;;         message id of beginning of theMessages
;; end tell")))
;;     (org-make-link-string (concat "message://" message-id) subject)))

;; (defun org-get-url-link ()
;;   (let ((subject (do-applescript "tell application \"Safari\"
;;         name of document of front window
;; end tell"))
;;         (url (do-applescript "tell application \"Safari\"
;;         URL of document of front window
;; end tell")))
;;     (org-make-link-string url subject)))

;; (defun org-get-file-link ()
;;   (let ((subject (do-applescript "tell application \"Finder\"
;; 	set theItems to the selection
;; 	name of beginning of theItems
;; end tell"))
;;         (path (do-applescript "tell application \"Finder\"
;; 	set theItems to the selection
;; 	POSIX path of (beginning of theItems as text)
;; end tell")))
;;     (org-make-link-string (concat "file:" path) subject)))

;; (defun org-insert-message-link ()
;;   (interactive)
;;   (insert (org-get-message-link)))

;; (defun org-insert-url-link ()
;;   (interactive)
;;   (insert (org-get-url-link)))

;; (defun org-insert-file-link ()
;;   (interactive)
;;   (insert (org-get-file-link)))

;; (defun org-set-dtp-link ()
;;   "Set a property for the current headline."
;;   (interactive)
;;   (org-set-property "Document" (org-get-dtp-link)D))

;; (defun org-set-message-link ()
;;   "Set a property for the current headline."
;;   (interactive)
;;   (org-set-property "Message" (org-get-message-link)))

;; (defun org-set-url-link ()
;;   "Set a property for the current headline."
;;   (interactive)
;;   (org-set-property "URL" (org-get-url-link)))

;; (defun org-set-file-link ()
;;   "Set a property for the current headline."
;;   (interactive)
;;   (org-set-property "File" (org-get-file-link)))

;; (defun org-dtp-message-open ()
;;   "Visit the message with the given MESSAGE-ID.
;; This will use the command `open' with the message URL."
;;   (interactive)
;;   (re-search-backward "\\[\\[message://\\(.+?\\)\\]\\[")
;;   (do-applescript
;;    (format "tell application \"DEVONthink Pro\"
;; 	set searchResults to search \"%%3C%s%%3E\" within URLs
;; 	open window for record (get beginning of searchResults)
;; end tell" (match-string 1))))

;; (defun org-export-tasks ()
;;   (interactive)
;;   (let ((index 1))
;;    (org-map-entries
;;     #'(lambda ()
;; 	(outline-mark-subtree)
;; 	(org-export-as-html 3)
;; 	(write-file (format "%d.html" index))
;; 	(kill-buffer (current-buffer))
;; 	(setq index (1+ index)))
;;     "LEVEL=2")))

;; (defun org-make-regress-test ()
;;   (interactive)
;;   (save-excursion
;;     (outline-previous-visible-heading 1)
;;     (let ((begin (point))
;; 	  (end (save-excursion
;; 		 (outline-next-heading)
;; 		 (point)))
;; 	  (input "\n") (data "") (output ""))
;;       (goto-char begin)
;;       (when (re-search-forward ":SCRIPT:\n" end t)
;; 	(goto-char (match-end 0))
;; 	(let ((input-beg (point)))
;; 	  (re-search-forward "[ 	]+:END:")
;; 	  (setq input (buffer-substring input-beg (match-beginning 0)))))
;;       (goto-char begin)
;;       (when (search-forward ":\\(DATA\\|SOURCE\\):\n" end t)
;; 	(goto-char (match-end 0))
;; 	(let ((data-beg (point)))
;; 	  (re-search-forward "[ 	]+:END:")
;; 	  (setq data (buffer-substring data-beg (match-beginning 0)))))
;;       (goto-char begin)
;;       (when (search-forward ":OUTPUT:\n" end t)
;; 	(goto-char (match-end 0))
;; 	(let ((output-beg (point)))
;; 	  (re-search-forward "[ 	]+:END:")
;; 	  (setq output (buffer-substring output-beg (match-beginning 0)))))
;;       (goto-char begin)
;;       (when (re-search-forward ":ID:\\s-+\\([^-]+\\)" end t)
;; 	(find-file (expand-file-name (concat (match-string 1) ".test")
;; 				     "~/src/ledger/test/regress/"))
;; 	(insert input "<<<\n" data ">>>1\n" output ">>>2\n=== 0\n")
;; 	(pop-to-buffer (current-buffer))
;; 	(goto-char (point-min))))))

;; (fset 'sort-todo-categories
;;    [?\C-u ?\C-s ?^ ?\\ ?* ?\S-  ?\C-a ?^ ?a ?^ ?p ?^ ?o ?\C-e])


(message "hey fritz - we finished loading wiegley emacs org code and wiegley-org.el code for using org and gtd")

(message "hey fritz - we are loading our iimage.el allowing us to inline images into org and other files")

(load-file (w32-short-file-name "~/.emacs.d/iimage.el"))
(autoload 'iimage-mode "iimage" "Support Inline image minor mode." t)
(autoload 'turn-on-iimage-mode "iimage" "Turn on Inline image minor mode." t)
(add-hook 'info-mode-hook 'turn-on-iimage-mode)
;;
;; .texinfo:   @file{file://foo.png}
;; .info:      `file://foo.png'
;;
;; ** Display images in Wiki buffer.
;;
(add-hook 'wiki-mode-hook 'turn-on-iimage-mode)
;;
;; wiki-file:   [[foo.png]]

(message "hey fritz - we've finished loading our iimage.el allowing us to inline images into org and other files")

(message "hey fritz - we are loading our org-utils.el which add some convenient keyboard shortcuts to work with images and a few other goodies")

;(load-file (w32-short-file-name "~/.emacs.d/org-utils.el"))

(message "hey fritz - we've finished loading our org-utils.el")

(defalias 'list-buffers 'ibuffer)
(message "hey fritz - you just replaced list-buffers with ibuffer")

   
(message "hey fritz - we are fixing an emacs bug such that when you open a “.xml” file, the file is opened with the old xml mode the sgm-mode, not nxml-mode")

(add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode))


;;; this must be loaded after the (load ... eli/fi-site-init.el) 
;;; to solve a compatibilty problem

(setq fi:eli-compatibility-mode nil)

(defun alisp ()
  (interactive)
  (let ((lisp-directory "C:\\Program Files\\acl81\\")
        (lisp-name "mlisp"))
    (fi:common-lisp (format "*%s*" lisp-name)
                    lisp-directory
                    (format "%s\\%s.exe" lisp-directory lisp-name)
                    (list "+B" "+cx" "+M")
                    fi:common-lisp-host
                    (format "%s.dxl" lisp-name))))



(defun add-to-load-path (path-string)
  (message (format "Passed %S..." path-string))
  (if (stringp path-string)
      (when (file-exists-p path-string)
	(message (format "Adding %S to load-path..." path-string))
	(add-to-list 'load-path (expand-file-name path-string)))
    (crs-add-to-load-path (car path-string))
    (if (cdr path-string)
	(crs-add-to-load-path (cdr path-string)))))


(message "Initialization complete") (sit-for 1)

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "SystemWindow" :foreground "SystemWindowText" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 158 :width normal :foundry "outline" :family "Arial Unicode MS")))))



(put 'upcase-region 'disabled nil)

(put 'downcase-region 'disabled nil)

(put 'narrow-to-region 'disabled nil)
